Computer programs have an execution flow governed by their compiled statements. Altering the execution flow of programs from its usual course is required in many instances for testing or experimentation purposes, or simply to assist an understanding of how the computer program operates. Currently there are two particular techniques that can be used to alter the flow of execution of a computer program.
A first technique involves changing the code, and recompiling the program, so that the required change in execution flow is achieved. A disadvantage of this first code-changing techniques is that recompilation is necessary. If the programmer wants to alter the execution for one run only, then the change must be made and the program recompiled. After testing, the change needs to be reverted and the program recompiled yet again. Importantly, recompilation may not even be a feasible option if the build takes too long. This is true for products with a significant code base.
A second technique involves changing an instruction pointer while the program is running. A programmer can change the instruction pointer using a debugger to suspend execution of the program at a particular point, and manually set the next statement. Most debuggers have a “Set Next Statement” or similar option providing an equivalent function. This changes the flow by changing the current point of execution. The debugger controls the child program and can alter the child's register contents. The above is achieved by altering the instruction pointer of the child program.
The second technique involving the instruction pointer also has disadvantages. Perhaps most critically, this second technique relies on manual intervention on the part of the programmer each time the program's flow is to be altered. Thus, the technique can often be impractical if the location at which the flow needs to be changed is called very frequently. As an example, consider a code location that is called 1000 times, which is not unlikely for a computer program. To achieve the effect of the altered flow, the programmer needs to perform the manual steps 1000 times. This phenomenon arises regardless of whether the flow needs to be altered in a loop, or in a method that is called very frequently. Needless to say, this approach soon becomes impractical in such situations.
Consequently, a need clearly exists for an improved manner of altering the execution flow of computer programs.